var ClubGroup_MainWindow = Window.extend({
    _ccsFileName: res.ClubGroup_MainWindow_json,
    _clubId: null,
    _clubInfo: null,
    _panelClassName0: {
        0: 'ClubGroup_Hequnshuju',   //
        1: 'ClubGroup_Hehuorenchengyuan',   //
        2: 'ClubGroup_Chengyuanfenpei',   //
        3: 'ClubGroup_Hequnrizhi',   //
    },
    _panelClassName1: {
        10: 'ClubQuit',   //退出
    },
    _curPanel: null,
    _curPanelLen: 0,
    _curSelectedTab: null,
    _isAdmin: false,
    initWindow: function (clubId) {
        this._clubId = clubId;
        var clubInfo = ClubDataManager.getClubData(clubId);
        this._isAdmin = ClubDataManager.isSelfAdministration(clubId, gameData.uid);

        //if (this._isAdmin) {
            this._nodeList['container.p_tab_0'].setVisible(true);
            this._nodeList['container.p_tab_1'].setVisible(false);
            this._curPanel = this._panelClassName0;
            this._curSelectedTab = 0;
        //}
        //else {
        //    this._nodeList['container.p_tab_0'].setVisible(false);
        //    this._nodeList['container.p_tab_1'].setVisible(true);
        //    this._curPanel = this._panelClassName1;
        //    this._curSelectedTab = 10;
        //}

        var count = 0;
        var tmpTab = null;
        for (var item in this._curPanel){
            // if (this._isAdmin){
                tmpTab = this._nodeList['container.p_tab_0.tab' + item];
                tmpTab.index = item;
                tmpTab.viewTab =this._curPanel[item];
            // }
            // else {
            //     tmpTab = this._nodeList['container.p_tab_1.tab' + item];
            //     tmpTab.index = item;
            //     tmpTab.viewTab =this._curPanel[item];
            // }
            count ++;
        }
        this._curPanelLen = count;
        this._changeTab(this._curSelectedTab);
    },

    _initClickListeners: function () {
        this._clickListeners = {
            'btn_close': '_clickClose',
        };
        for (var item in this._panelClassName0){
            this._clickListeners['container.p_tab_0.tab' + item] = '_clickTab';
        }
        for (var item in this._panelClassName1){
            this._clickListeners['container.p_tab_1.tab' + item] = '_clickTab';
        }
    },

    _clickTab: function (target) {
        this._changeTab(target.index);
    },

    _changeTab: function (tab) {
        if (this._currentSelectTab == tab) return;
        this._currentSelectTab = tab;
        var viewTab = null;
        //var prefix = this._isAdmin ? "container.p_tab_0" : "container.p_tab_1";
        var prefix = "container.p_tab_0";

        for (var i in this._curPanel) {
            var select = (i == this._currentSelectTab);
            var viewTabTemp = this._nodeList[prefix +'.tab' + i].viewTab;
            if (select) {
                viewTab = viewTabTemp;
            }
            if (this[viewTabTemp] && cc.sys.isObjectValid(this[viewTabTemp])) {
                this[viewTabTemp].removeFromParent();
                this[viewTabTemp] = null;
            }
            this._nodeList[prefix +'.tab' + i + '.select'].setVisible(select);
            this._nodeList[prefix +'.tab' + i + '.unselect'].setVisible(!select);
        }

        var tabLayer = this[viewTab];
        if (!tabLayer || !cc.sys.isObjectValid(tabLayer)) {
            this[viewTab] = addItem(viewTab, this._nodeList['container.content'], this._clubId);
            tabLayer = this[viewTab];
        }
        if (!tabLayer || !cc.sys.isObjectValid(tabLayer)) return;
        tabLayer.setVisible(true);
        if (tabLayer['refreshView']) {
            tabLayer.refreshView();
        }
    },

    _clickClose: function () {
        this.close();
    },
});